package com.common.resolve;

import cn.hutool.core.io.IoUtil;
import cn.hutool.http.ContentType;
import cn.hutool.json.JSONObject;
import com.common.exception.ErrorException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.Part;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Component;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Collection;

/**
 * @Description:
 * @Date: 2025/7/7 11:44
 */
@Component
public class MultipartFormContentTypeResolve implements ContentTypeResolve {
    @Override
    public ContentType contentType() {
        return ContentType.MULTIPART;
    }

    @Override
    public JSONObject resolve(ServletRequest servletRequest, ServletResponse servletResponse) {
        try {
            Collection<Part> parts = ((HttpServletRequest) servletRequest).getParts();
            if (!parts.isEmpty()){
                for (Part part : parts) {
                    InputStream inputStream = part.getInputStream();

                }
            }
        } catch (Exception e) {
            throw new ErrorException(e.getMessage());
        }
        return null;
    }
}
